﻿using System;
using System.Collections.Generic;
using System.Text;
using AutoShutdownDotNet.DataAccess;

namespace AutoShutdownDotNet.Models
{
    public class Setting
    {
        public int Id { get; set; }
        public bool StartWithWindows { get; set; }
        public string Password { get; set; }
        public AutoShutdownView View { get; set; }
        public AutoShutdownWinState WindowsState { get; set; }
        public bool FirstRun { get; set; }
        public DateTime FirstRunDate { get; set; }
        public DateTime LastRunDate { get; set; }
        public bool PasswordProtected
        {
            get { return (Password != string.Empty); }
        }

        public static void Update(Setting setting)
        {
            Database db = new Database();
            Setting defaultSetting = db.GetDefaultSetting();
            if(defaultSetting == null)
                db.Insert(setting);
            else
                db.Update(setting);
        }

        public void Update()
        {
            Database db = new Database();
            db.Update(this);
        }

        public static  Setting GetDefault()
        {
            return new Database().GetDefaultSetting();
        }


    }
}
